package mh.modules.mh.controller;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.Date;
import java.util.Map;

import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import mh.modules.mh.entity.GrowthEntity;
import mh.modules.mh.service.GrowthService;
import mh.common.utils.PageUtils;
import mh.common.utils.R;



/**
 * 
 *
 * @author zhongxiang
 * @email 
 * @date 2024-10-23 16:59:34
 */
@RestController
@RequestMapping("mh/growth")
@Slf4j
public class GrowthController {
    @Autowired
    private GrowthService growthService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("mh:growth:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = growthService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{mhId}")
    @RequiresPermissions("mh:growth:info")
    public R info(@PathVariable("mhId") Long mhId){
		GrowthEntity growth = growthService.getById(mhId);

        return R.ok().put("growth", growth);
    }

    /**
     * 保存棉花（生长）信息
     */
    @RequestMapping("/save")
    @RequiresPermissions("mh:growth:save")
    public R save(@RequestBody GrowthEntity growth){
//        log.info("GrowthEntity{}",growth);
		boolean save = growthService.saveGrowth(growth);
        return R.ok("保存结果"+save);
    }


    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("mh:growth:update")
    public R update(@RequestBody GrowthEntity growth){
//        log.info("GrowthEntity{}",growth);
       boolean update = growthService.updateGrowth(growth);

        return R.ok("保存结果"+update);
    }

    /**
     * 删除(株树变化更新状态)
     */
    @RequestMapping("/delete")
    @RequiresPermissions("mh:growth:delete")
    public R delete(@RequestBody Long[] mhIds){
//        log.info("删除的ID为{}"+mhIds+"序列化后"+Arrays.asList(mhIds));
	    boolean delete = growthService.removeByGrowthIds(Arrays.asList(mhIds));

        return R.ok("删除结果"+delete);
    }
    /**
     * 柱状图
     */
    @RequestMapping("/growthbar")
    public R growthBar(){

        R r = growthService.growthBar();

        return R.ok(r);
    }


}
